/*
 * @Author: yanjikun
 * @Date: 2021-06-28 10:24:20
 * @LastEditors: yanjikun
 * @LastEditTime: 2022-05-16 15:20:21
 * @Description: file content
 */

import { isObject } from 'lodash'
import type { App, Plugin } from 'vue'

export const componentInstall = <T>(component: T, alias?: string) => {
  const comp = component as any
  comp.install = (app: App) => {
    app.component(comp.name || comp.displayName, component)
    if (alias) {
      app.config.globalProperties[alias] = component
    }
  }
  return component as T & Plugin
}

export function deepMerge<T = any>(src: any = {}, target: any = {}): T {
  let key: string
  for (key in target) {
    src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key])
  }
  return src
}
